package com.bicon.botu.mall.goods.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.mall.goods.service.NoticeOfReductionService;
import com.bicon.botu.mall.goods.vo.NoticeOfReductionVo;
import com.bicon.botu.mall.goods.vo.PriceDownNoticeVo;
import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 降价通知Controller
 *
 * @Author 刘齐
 * @Date 2017/7/25 10:19
 */
@RestController
@RequestMapping("/V1.0.0/NoticeOfReductionController")
public class NoticeOfReductionController extends BaseController {
    //降价通知Service
    @Autowired
    NoticeOfReductionService noticeOfReductionService;



    /**
     * 商家通知
     *
     * @param id 降价通知ID
     * @return
     */
    @RequestMapping(value = "/merchantsNotice", method = RequestMethod.GET)
    public BaseResult merchantsNotice(String id) {
        return noticeOfReductionService.merchantsNotice(id);
    }

    /**
     * 降价通知分页
     *
     * @param current 当前页
     * @param size    每页条数
     * @return
     */
    @RequestMapping(value = "/selectNoticePage", method = RequestMethod.POST)
    public BaseResult selectNoticePage(@RequestParam Integer current, @RequestParam Integer size) {
        Page<NoticeOfReductionVo> page = new Page<NoticeOfReductionVo>(current, size);
        page.setOrderByField("nr.create_date");
        page.setAsc(false);
        List<NoticeOfReductionVo> noticeOfReductionVo = noticeOfReductionService.selectNoticePage(page);
        page.setRecords(noticeOfReductionVo);
       // page.setAsc(true);
        if (page == null) {
            return sendResult(Constants.RESPONSE_CODE_600, Constants.RESPONSE_MESSAGE_600);
        }
        return sendResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, page);
    }

    /**
     * 自动发送降价通知
     *
     * @param priceDownNoticeVoListJson Json字符串实体
     * @return
     */
    @RequestMapping(value = "/systemInfo", method = RequestMethod.POST)
    public BaseResult systemInfo(String priceDownNoticeVoListJson) {
        List<PriceDownNoticeVo> priceDownNoticeVoList = JSONObject.parseArray(priceDownNoticeVoListJson, PriceDownNoticeVo.class);
        return noticeOfReductionService.systemInfo(priceDownNoticeVoList);
    }

}
